<?php

namespace common\models\demand;

use Yii;

/**
 * This is the model class for table "{{%demand_solution}}".
 *
 * @property int $id
 * @property string $title
 * @property string|null $description
 * @property int $user_id
 * @property int $demand_id
 * @property int $status
 * @property int $created_at
 * @property int $updated_at
 * @property int $deleted_at
 */
class DemandSolution extends \common\db\ActiveRecord {

    use \common\traits\relation\User;

    /**
     * 状态
     */
    const STATUS_ACTIVE = 10;
    const STATUS_DEFAULT = 0;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%demand_solution}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['user_id', 'demand_id', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['title'], 'required'],
            [['title'], 'string', 'max' => 255],
            [['content'], 'string', 'max' => 1000],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'user_id' => 'user_id',
            'demand_id' => 'Channel ID',
            'title' => 'Title',
            'content' => 'content',
            'status' => 'Status',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'deleted_at' => 'Deleted At',
        ];
    }

    public function getPublishTime() {
        return date('m-d H:i', $this->created_at);
    }

    public function fields() {
        return [
            'id',
            'title',
            'user',
            'publish_time' => 'publishTime',
        ];
    }

}
